package com.sebiotec.manager.adapt;

import android.content.Intent;
import android.view.View;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import com.sebiotec.manager.R;
import com.sebiotec.manager.model.MessageEntity;
import com.sebiotec.manager.ui.activity.MessageDetailActivity;
import com.sebiotec.manager.ui.view.MaterialBadgeTextView;
import com.mcxtzhang.swipemenulib.SwipeMenuLayout;

import java.util.List;

public class MessageAdapt extends BaseQuickAdapter<MessageEntity, BaseViewHolder> {







    public MessageAdapt(int layoutResId, @Nullable List<MessageEntity> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, MessageEntity item) {
        SwipeMenuLayout viewById1 = helper.itemView.findViewById(R.id.sw);

        helper.itemView.findViewById(R.id.cl_ll).setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                viewById1.smoothExpand();
                return true;
            }
        });
        viewById1.setSwipeEnable(false);
        helper.setText(R.id.tv_message_name,item.getName());
        helper.setText(R.id.tv_clue_time,item.getTime());
        MaterialBadgeTextView viewById = helper.itemView.findViewById(R.id.xhd);
        helper.itemView.findViewById(R.id.cl_ll).setOnClickListener(v->{

              if (viewById1.isExpanding()){
                 viewById1.smoothClose();
              }else{
                  Intent   intent =new Intent(getContext(), MessageDetailActivity.class);
                  intent.putExtra("pos",helper.getLayoutPosition());
                  getContext().startActivity(intent);
              }


        });
        helper.itemView.findViewById(R.id.iv_delete).setOnClickListener(v->{
             getData().remove(helper.getLayoutPosition());
            notifyItemRemoved(helper.getLayoutPosition());//刷新被删除的地方
            notifyItemRangeChanged(helper.getLayoutPosition(), getItemCount()); //刷新被删除数据，以及其后面的数据
        });
        viewById.setBadgeCount(item.getSum(),true);

    }
}